'use strict';

const Controller = require('egg').Controller;


function toInt(str) {
  if (typeof str === 'number') return str;
  if (!str) return str;
  return parseInt(str, 10) || 0;
}


class TipsController extends Controller {

  async index() {
    const ctx = this.ctx;
    const query = { limit: toInt(ctx.query.limit), offset: toInt(ctx.query.offset) };
    ctx.body = await ctx.model.Tips.findAll(query);
  }

  async getOne() {
    const ctx = this.ctx;
    ctx.body = await ctx.model.Tips.findByPk(1);
  }


  async tolist() {
    const { ctx } = this;
    await ctx.render('tips.html');
  }

  async towelcome() {
    const { ctx } = this;
    await ctx.render('welcome.html');
  }

}

module.exports = TipsController;
